package com.zj.core.ui

import android.content.Context
import android.graphics.Color
import android.support.constraint.ConstraintLayout
import android.view.Gravity
import android.view.View
import android.view.ViewManager
import android.widget.*
import com.customcamera.widget.CameraContainer
import com.zj.core.R
import com.zj.core.view.RichEditText
import org.jetbrains.anko.*
import org.jetbrains.anko.constraint.layout.constraintLayout
import org.jetbrains.anko.constraint.layout.guideline
import org.jetbrains.anko.custom.ankoView

class TemplateChangeUI(context: Context, listener: View.OnClickListener) {
    private var mContext: Context = context
    private var mClickListener: View.OnClickListener = listener

    var common_dialog_title_tv: TextView? = null
    var template_edit: RichEditText? = null
    var common_dialog_cancel_tv: TextView? = null
    var common_dialog_vertical_line: View? = null
    var common_dialog_confirm_tv: TextView? = null
    var common_dialog_root_view: RelativeLayout? = null

    lateinit var voiceImgView: ImageView

    init {
        common_dialog_root_view = mContext.relativeLayout {
            lparams(width = matchParent, height = matchParent)

            linearLayout {
                background = resources.getDrawable(R.drawable.popup_dialog_bg)
                orientation = LinearLayout.VERTICAL

                common_dialog_title_tv = textView {
                    id = R.id.common_dialog_title_tv
                    text = "表单列表"
                    textSize = dip(12).toFloat()
                    textColor = Color.parseColor("#555555")
                    gravity = Gravity.CENTER
                }.lparams(width = matchParent, height = wrapContent) {
                    topMargin = dip(15)
                    bottomMargin = dip(15)
                }

                view {
                    backgroundColor = Color.parseColor("#F5F5F5")
                }.lparams(width = matchParent, height = dip(1))

                template_edit = richEditText {
                    id = R.id.record_template_change
                    gravity = Gravity.START
                    textSize=20F
                    background = null
                }.lparams(width = matchParent, height = dip(0)) {
                    weight = 1F
                }

                view {
                    backgroundColor = Color.parseColor("#F5F5F5")
                }.lparams(width = matchParent, height = dip(1))

                linearLayout {
                    id = R.id.common_dialog_bottom_ll
                    orientation = LinearLayout.HORIZONTAL

                    common_dialog_cancel_tv = textView {
                        id = R.id.common_dialog_cancel_tv
                        gravity = Gravity.CENTER
                        text = "取消"
                        setOnClickListener(mClickListener)
                        textSize = dip(10).toFloat()
                        textColor = Color.parseColor("#0679FE")
                    }.lparams(width = 0, height = matchParent) {
                        weight = 1F
                        isClickable = true
                    }

                    common_dialog_vertical_line = view {
                        id = R.id.common_dialog_vertical_line
                        backgroundColor = Color.parseColor("#F5F5F5")
                    }.lparams(width = dip(1), height = matchParent)

                    common_dialog_confirm_tv = textView {
                        text = "确定"
                        setOnClickListener(mClickListener)
                        textSize = dip(10).toFloat()
                        textColor = Color.parseColor("#0679FE")
                        gravity = Gravity.CENTER
                        id = R.id.common_dialog_confirm_tv
                    }.lparams(width = 0, height = matchParent) {
                        weight = 1F
                        isClickable = true
                    }
                }.lparams(width = matchParent, height = dip(50))
            }.lparams(width = matchParent, height =matchParent)

            voiceImgView=imageView{
                id=R.id.voice_img_view
                visibility=View.GONE
                image=context.resources.getDrawable(R.mipmap.ease_record_animate_01)
                background=context.resources.getDrawable(R.drawable.border_line_voice_view)
                padding=15
            }.lparams(width=150,height = 150){
                centerInParent()
            }
        }
    }

    inline fun ViewManager.richEditText(theme: Int = 0, init: RichEditText.() -> Unit) : RichEditText {
        return ankoView({ RichEditText(it) }, theme, init)
    }
}